package com.freshfresh.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.freshfresh.activity.R;
import com.freshfresh.utils.ImageLoadOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

public class BannerAdapter extends BaseVPAdapter<View>
{
  private List<String> imgsrc = new ArrayList();

  public BannerAdapter(ArrayList<View> paramArrayList, Context paramContext)
  {
    super(paramArrayList, paramContext);
  }

  public BannerAdapter(ArrayList<View> paramArrayList, List<String> paramList, Context paramContext)
  {
    super(paramArrayList, paramContext);
    this.imgsrc = paramList;
  }

  public int getCount()
  {
    int i = 1;
    if ((this.mList == null) || (this.mList.size() == 0))
      i = 0;
    while (this.mList.size() == i)
      return i;
    return 10000;
  }

  public Object instantiateItem(ViewGroup paramViewGroup, final int paramInt)
  {
    final ImageView localImageView = new ImageView(this.mContext);
    localImageView.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
    localImageView.setScaleType(ImageView.ScaleType.FIT_XY);
    localImageView.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        if (BannerAdapter.this.listener != null)
          BannerAdapter.this.listener.onCustomerListener(localImageView, paramInt % BannerAdapter.this.mList.size());
      }
    });
    if ((this.imgsrc != null) && (this.imgsrc.size() != 0))
    {
      String str = (String)this.imgsrc.get(paramInt % this.mList.size());
      ImageLoader.getInstance().displayImage(str, localImageView, ImageLoadOptions.getOptions(0));
      if (TextUtils.isEmpty(str))
        localImageView.setImageResource(R.drawable.ic_default);
    }
    while (true)
    {
      paramViewGroup.addView(localImageView);
      localImageView.setImageResource(R.drawable.ic_default);
      return localImageView;
    }
  }
}